package com.vitabuybuy.tv.network

import com.library.common.net.NetUrl
import com.vitabuybuy.tv.dto.*
import rxhttp.IAwait
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * 作者：SimGa
 * 日期：2021/4/10
 * 时间：15:14
 * 包名：com.vitabuybuy.tv.network
 */
object TalentWalletRepository {
    fun getMyWallet(): IAwait<TalentWalletDto> {
        return RxHttp.postJson(NetUrl.api_get_talent_wallet_info).toResponse()
    }
    fun getRecordDetail(id:Int?): IAwait<RecordDetailDto> {
        return RxHttp.postJson(NetUrl.api_flow_get)
            .add("id",id)
            .toResponse()
    }

    fun withDraw(amount: String, bankCardId: Int): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_talent_with_draw).add("amount", amount)
            .add("bankCardId", bankCardId).toResponse()
    }


    fun getBankCardList(
        pageNumber: Int,
        pageSize: Int
    ): IAwait<MutableList<BankCardListDto>> {
        val params = mapOf(
            Pair(
                "pageable",
                mapOf(
                    Pair("page", pageNumber),
                    Pair("size", pageSize),
                    Pair("desc", "id")
                )
            )
        )
        return RxHttp.postJson(NetUrl.api_find_talent_all_bank_card)
            .addAll(params).toResponse()
    }

    fun addNewBankCard(params: Map<String, Any>): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_talent_add_new_bank_card)
            .add("bankCard", params).toResponse()
    }


    fun getBillList(
        type: String?,
        pageNumber: Int,
        pageSize: Int
    ): IAwait<MutableList<BillListDto>> {
        val params = HashMap<String, Any?>().apply {
            this["type"] = type
            this["pageable"] = mapOf(
                Pair("page", pageNumber),
                Pair("size", pageSize),
                Pair("desc", "id")
            )
        }
        return RxHttp.postJson(NetUrl.api_talent_with_draw_bill)
            .addAll(params).toResponse()
    }

    fun getMyGoldWallet(): IAwait<Int> {
        return RxHttp.postJson(NetUrl.api_get_gold_amount).toResponse()
    }

    fun withDrawQuantity(drawQuantity: Int): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_rewardrecord)
            .add("goldQuantity", drawQuantity)
            .toResponse()
    }


    fun getGoldRecordList(
        type: String?,
        pageNumber: Int,
        pageSize: Int
    ): IAwait<MutableList<GoldRecordListDto>> {
        val params = HashMap<String, Any?>().apply {
            this["type"] = type
            this["pageable"] = mapOf(
                Pair("page", pageNumber),
                Pair("size", pageSize),
                Pair("desc", "id")
            )
        }
        return RxHttp.postJson(NetUrl.api_record)
            .addAll(params).toResponse()
    }
}